import request from '@/utils/request';

/**
 * 分页查询用户
 */
export async function get_list(params) {
  const res = await request.post('/purchase/receipts_distribute/get_list', {
    ...params
  });
  if (res.data.code === 1) {
    return {
      list: res.data.data.row_list,
      columns: res.data.data.columns,
      searchData: res.data.data.search_area,
      count: res.data.data.page_info?.total,
      top_button: res.data.data.top_button
    };
  }
  return Promise.reject(res.data.msg);
}
/* 库存统计 */
export async function get_goods_list(params) {
  const res = await request.post('/purchase/goods_info/get_list', {
    ...params
  });
  if (res.data.code === 1) {
    return {
      list: res.data.data.row_list,
      columns: res.data.data.columns,
      searchData: res.data.data.search_area,
      count: res.data.data.page_info?.total
    };
  }
  return Promise.reject(res.data.msg);
}
/* 选择货品 */
export async function get_goods_list2(params) {
  const res = await request.post('/warehouse/goods_info/get_list', {
    ...params
  });
  if (res.data.code === 1) {
    res.data.data.row_list.forEach((item) => {
      item.sku_info.forEach((m) => {
        item[m.column] =
          m.column_type == 'select' ||
          m.column_type == 'selectajax' ||
          m.column_type == 'selectajaxlike'
            ? m.value_name
            : m.value;
      });
    });
    let columns = [
      {
        title: '条码',
        field: 'bar_code',
        name: 'bar_code',
        table: ''
      },
      {
        title: '货品名称',
        field: 'name',
        name: 'name',
        table: ''
      },
      {
        title: '货品位置',
        field: 'type_code_name',
        name: 'type_code_name',
        table: ''
      },
      {
        title: '货品小类',
        field: 'subclass_code',
        name: 'subclass_code',
        table: ''
      },
      {
        title: '成色',
        field: 'quality_code',
        name: 'quality_code',
        table: ''
      },
      {
        title: '货品品类',
        field: 'classes_code',
        name: 'classes_code',
        table: ''
      },
      {
        title: '供应商',
        field: 'supplier_code',
        name: 'supplier_code',
        table: ''
      },
      {
        title: '账面库存',
        field: 'paper_num',
        name: 'paper_num',
        table: ''
      },
      {
        title: '可用库存',
        field: 'num',
        name: 'num',
        table: ''
      }
    ];
    return {
      list: res.data.data.row_list,
      columns: columns,
      searchData: res.data.data.search_area,
      count: res.data.data.page_info?.total
    };
  }
  return Promise.reject(res.data.msg);
}

/* 分配单单详情 */
export async function receipts_distribute_detail(params) {
  const res = await request.post(
    '/purchase/receipts_distribute/detail',
    params
  );
  if (res.data.code === 1) {
    return res.data.data;
  }
  return Promise.reject(res.data.msg);
}
/* 作废采购单 */
export async function cancel_purchase(params) {
  const res = await request.post(
    '/purchase/receipts_distribute/cancel_distribute',
    params
  );
  if (res.data.code === 1) {
    return res.data;
  }
  return Promise.reject(res.data.msg);
}
/* 删除采购单 */
export async function del_receipts(params) {
  const res = await request.post(
    '/purchase/receipts_distribute/del_receipts',
    params
  );
  if (res.data.code === 1) {
    return res.data;
  }
  return Promise.reject(res.data.msg);
}
/* 反审 采购单*/
export async function back_verify(params) {
  const res = await request.post(
    '/purchase/receipts_distribute/back_verify',
    params
  );
  if (res.data.code === 1) {
    return res.data;
  }
  return Promise.reject(res.data.msg);
}
/* 取消审核采购单 */
export async function cancel_verify(params) {
  const res = await request.post(
    '/purchase/receipts_distribute/cancel_verify',
    params
  );
  if (res.data.code === 1) {
    return res.data;
  }
  return Promise.reject(res.data.msg);
}
/* 提交审核采购单 */
export async function confirm_purchase(params) {
  const res = await request.post(
    '/purchase/receipts_distribute/confirm_distribute',
    params
  );
  if (res.data.code === 1) {
    return res.data;
  }
  return Promise.reject(res.data.msg);
}

/* 添加货品 */
export async function add_goods(params) {
  const res = await request.post(
    '/purchase/receipts_distribute/add_goods',
    params
  );
  if (res.data.code === 1) {
    return res.data;
  }
  return Promise.reject(res.data.msg);
}

/* 货品详情 */
export async function goods_detail(params) {
  const res = await request.post(
    '/purchase/receipts_distribute/goods_detail',
    params
  );
  if (res.data.code === 1) {
    return res.data.data;
  }
  return Promise.reject(res.data.msg);
}

/* 删除货品 */
export async function del_goods(params) {
  const res = await request.post(
    '/purchase/receipts_distribute/del_goods',
    params
  );
  if (res.data.code === 1) {
    return res.data;
  }
  return Promise.reject(res.data.msg);
}
/* 总部返厂批量录入 */
export async function batch_enter(params) {
  const res = await request.post(
    '/purchase/receipts_distribute/batch_enter',
    params
  );
  if (res.data.code === 1) {
    return res.data;
  }
  return Promise.reject(res.data.msg);
}
/* 编辑货品 */
/* export async function edit_goods(params) {
  const res = await request.post('/purchase/receipts_distribute/edit_goods', params);
  if (res.data.code === 1) {
    return res.data;
  }
  return Promise.reject(res.data.msg);
} */
